/********************************** (C) COPYRIGHT *******************************
 * File Name          : usb_desc.c
 * Author             : WCH
 * Version            : V1.0.0
 * Date               : 2022/08/20
 * Description        : usb device descriptor,configuration descriptor,
 *                      string descriptors and other descriptors.
 *********************************************************************************
 * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
 * Attention: This software (modified or not) and binary are used for
 * microcontroller manufactured by Nanjing Qinheng Microelectronics.
 *******************************************************************************/

#include "usb_desc.h"

/* Device Descriptor */
const USB_DEVICE_DESCRIPTOR MyDevDescr =
    {
        .bLength = 0x12,                        // bLength
        .bDescriptorType = 0x01,                // bDescriptorType (Device)
        .bcdUSB = 0x0200,                       // bcdUSB 1.10
        .bDeviceClass = 0xFF,                   // bDeviceClass
        .bDeviceSubClass = 0xFF,                // bDeviceSubClass
        .bDeviceProtocol = 0xFF,                // bDeviceProtocol
        .bMaxPacketSize0 = DEF_USBD_UEP0_SIZE,  // bMaxPacketSize0 64
        .idVendor = DEF_USB_VID,                // idVendor 0x1A86
        .idProduct = DEF_USB_PID,               // idProduct 0xFE0C
        .bcdDevice = DEF_IC_PRG_VER,            // bcdDevice 0.01
        .iManufacturer = 0x01,                  // iManufacturer (String Index)
        .iProduct = 0x02,                       // iProduct (String Index)
        .iSerialNumber = 0x00,                  // iSerialNumber (String Index)
        .bNumConfigurations = 0x01,             // bNumConfigurations 1
};

/* Configuration Descriptor */
const USBConfiguration
    MyCfgDescr =
        {
            {.bLength = 0x09,  //  configure
             .bDescriptorType = 0x02,
             .wTotalLength = sizeof (MyCfgDescr),
             .bNumInterfaces = 0x01,
             .bConfigurationValue = 0x01,
             .iConfiguration = 0x02,
             .bmAttributes = 0x80,
             .MaxPower = 0x32},
            {.bLength = 0x09,  // interface 0 Alter 0
             .bDescriptorType = 0x04,
             .bInterfaceNumber = 0x00,
             .bAlternateSetting = 0x00,
             .bNumEndpoints = 0x02,
             .bInterfaceClass = 0xff,
             .bInterfaceSubClass = 0x01,
             .bInterfaceProtocol = 0x01,
             .iInterface = 0x02},

            {.bLength = 0x07,  // endpoint 2
             .bDescriptorType = 0x05,
             .bEndpointAddress = 0x02,
             .bmAttributes = 0x02,
             .wMaxPacketSize = DEF_USBD_ENDP2_SIZE,
             .bInterval = 0x00},

            {.bLength = 0x07,  // endpoint 3
             .bDescriptorType = 0x05,
             .bEndpointAddress = 0x83,
             .bmAttributes = 0x02,
             .wMaxPacketSize = DEF_USBD_ENDP3_SIZE,
             .bInterval = 0x00},
};


const USBD_StringDescriptor stringDescriptors = {
    {
     .Langid = USBD_STRDESC_LANGID,
     .len = 4,
     .type = USB_STRING_DESCRIPTOR_TYPE,
     },
    USBD_STR_VAL (STRDESC_MAN),
    USBD_STR_VAL (STRDESC_PROD),
    USBD_STR_VAL (STRDESC_SERIAL),
    USBD_STR_VAL (STRDESC_OS),
};
const u8 winUSB[] = {
    ///////////////////////////////////////
    /// WCID descriptor
    ///////////////////////////////////////
    0x28, 0x00, 0x00, 0x00,                   /* dwLength */
    0x00, 0x01,                               /* bcdVersion */
    0x04, 0x00,                               /* wIndex */
    0x01,                                     /* bCount */
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* bReserved_7 */
    ///////////////////////////////////////
    /// WCID function descriptor
    ///////////////////////////////////////
    0x00, /* bFirstInterfaceNumber */
    0x01, /* bReserved */
    /* WINUSB */
    'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, /* cCID_8 */
    /*  */
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* cSubCID_8 */
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00,             /* bReserved_6 */
};